package model; 

import org.dom4j.Branch;
import org.dom4j.Element;

public class Item {
	private String name;
	private String path;
	
	public Item() {
		
	}
	
	public Item(String name, String path) {
		this.name = name;
		this.path = path;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
	public void setQuantity(String path) {
		this.path = path;
	}
	
	public String getQuantity() {
		return path;
	}
	
	/**
	 * Convert this Item into an XML element.
	 * 
	 * @param parent the parent XML element or document
	 * @return the XML element created for this Item 
	 */
	public Element toElement(Branch parent) {
		Element element = parent.addElement("Item");
		Element name = element.addElement("Name");
		name.setText(this.name);
		Element quantity = element.addElement("Quantity");
		quantity.setText(String.valueOf(this.path));
		return element;
	}

	/**
	 * Initialize this Item based on the data stored
	 * in given XML element, which must be an Item element.
	 * 
	 * @param element the XML element containing the Item data
	 */
	public void fromElement(Element element) {
		name = element.selectSingleNode("//Item/Name").getText();
		path = element.selectSingleNode("//Item/Quantity").getText();
	}
}
